package chapter10;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-21 下午3:40
 */
public class DateTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(DateTest.class);

    public static void main(String[] args) {
        Date date = new Date();
        LOGGER.info("date:{}", date);
        LOGGER.info("get long time:{}", date.getTime());

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        LOGGER.info("format time:{}", dateFormat.format(date));
        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        LOGGER.info("format time:{}", dateFormat2.format(date));

        Calendar cal = Calendar.getInstance();
        StringBuffer sb = new StringBuffer();
        sb.append(cal.get(Calendar.YEAR)).append("-");
        sb.append(cal.get(Calendar.MONTH)+1).append("-");
        sb.append(cal.get(Calendar.DAY_OF_MONTH)).append(" ");
        sb.append(cal.get(Calendar.HOUR_OF_DAY)).append(":");
        sb.append(cal.get(Calendar.MINUTE)).append(":");
        sb.append(cal.get(Calendar.SECOND));

        LOGGER.info("calender:{}", sb);
    }
}
